package com.example.a13;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;

public class TestProxy {
    public static void main(String[] args) throws Exception {
        byte[] dump = $Proxy0Dump.dump();
/*
        FileOutputStream os = new FileOutputStream("$Proxy0.class");
        os.write(dump, 0, dump.length);
        os.close();
*/
        ClassLoader loader = new ClassLoader() {
            @Override
            protected Class<?> findClass(String name) throws ClassNotFoundException {
                return super.defineClass(name, dump, 0, dump.length);
            }
        };
        Class<?> aClass = loader.loadClass("com.example.a13.$Proxy0");
        Constructor<?> constructor = aClass.getConstructor(InvocationHandler.class);
        Foo foo = (Foo) constructor.newInstance((InvocationHandler) (proxy, method, args1) -> {
            System.out.println("before..");
            System.out.println("调用目标");
            return null;
        });

        foo.foo();
    }
}
